package com.huaxin.hxenum.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import com.huaxin.hxenum.base.BaseCodeEnum;

/**
 * 断路器状态
 */
public enum BreakerStatus implements BaseCodeEnum<String> {

    /**
     * 分闸 (Open)
     * 断路器处于断开状态
     */
    OPEN("open", "分闸"),

    /**
     * 合闸 (Closed)
     * 断路器处于闭合状态
     */
    CLOSED("closed", "合闸");

    @EnumValue
    private final String code;
    private final String displayName;

    BreakerStatus(String code, String displayName) {
        this.code = code;
        this.displayName = displayName;
    }

    @JsonValue
    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDisplayName() {
        return displayName;
    }

    public static BreakerStatus of(String code) {
        for (BreakerStatus status : values()) {
            if (status.getCode().equalsIgnoreCase(code)) {
                return status;
            }
        }
        return null;
    }

    public static boolean isValid(String code) {
        return of(code) != null;
    }
}